import { combineReducers, configureStore } from "@reduxjs/toolkit";
import userReducer from "./userSlice";
import { persistStore, persistReducer } from "redux-persist";
import storage from "redux-persist/lib/storage";

const persistConfig = {  //持久化的配置对象
    //数据存储
    key: "persist",               //自定义
    storage
}

const reducers = combineReducers({
    user: userReducer
})

const persistedReducer = persistReducer(persistConfig, reducers);

const store = configureStore({
    reducer: persistedReducer,
    middleware: getDefaultMiddleware => getDefaultMiddleware({  //解决动作无法序列化的问题
        //关闭redux序列化检测
        serializableCheck: false
    })

})

export const persistor = persistStore(store)

export default store